{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# 缠论数据图表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "import time\n",
    "\n",
    "from chanlun import kcharts\n",
    "from chanlun.cl_utils import query_cl_chart_config\n",
    "from chanlun.exchange import get_exchange\n",
    "from chanlun import cl\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 市场\n",
    "market = 'a'  # a 沪深A股  hk 港股 us 美股 futures 期货 currency 数字货币\n",
    "# 标的代码\n",
    "code = 'SH.603288'\n",
    "# 获取周期，可设置多个\n",
    "frequencys = ['5m']\n",
    "# 开始时间（需要api接口支持）\n",
    "start_date = None\n",
    "# 结束时间（需要api接口支持）\n",
    "end_date = None\n",
    "# 缠论计算配置\n",
    "cl_config = query_cl_chart_config(market, code)\n",
    "\n",
    "ex = get_exchange(market) # 使用在线的k线数据接口\n",
    "# ex = ExchangeDB(market) # 读取数据库中的k线数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "renders = []\n",
    "cl_datas = []\n",
    "\n",
    "_s = time.time()\n",
    "for f in frequencys:\n",
    "    klines = ex.klines(code, frequency=f, start_date=start_date, end_date=end_date)\n",
    "    # klines = klines[0:630:]\n",
    "    print(f, '获取K线数据量：', len(klines))\n",
    "    cl_datas.append(cl.CL(code, f, cl_config).process_klines(klines))\n",
    "print('Run time: ', time.time() - _s)\n",
    "\n",
    "for cd in cl_datas:\n",
    "    title = '%s - 【%s】 周期数据图表' % (code, cd.frequency)\n",
    "    renders.append(kcharts.render_charts(title, cd))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "is_executing": true,
     "name": "#%%\n"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "renders[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "is_executing": true,
     "name": "#%%\n"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "renders[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "renders[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "renders[3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "### 以下可以写自己代码获取所需并分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# 最后一个线段\n",
    "xd = cl_datas[0].xds[-1]\n",
    "print(xd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "tags": []
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
